From: Sergey Ponomarev Date: Sat, 1 Jun 2024 17:19:41 +0000 (+0300) Subject: luci-app-acme: Guess the system domain and pre-fill it to domains. X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22http:/www.crowdsec.net/%22/%22https:/collectd.org/%22http:/www.crowdsec.net/%22?a=commitdiff_plain;h=c4e38e2656d88fc83b3b7991c192184b2da8f2cc;p=project%2Fluci.git luci-app-acme: Guess the system domain and pre-fill it to domains. Check if the hostname is FQDN (e.g. has least one dot). Check if the domain in the browser is not an IP and FQDN. Signed-off-by: Sergey Ponomarev --- diff --git a/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js b/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js index 937a931269..c8f2a52116 100644 --- a/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js +++ b/applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js @@ -19,6 +19,7 @@ return view.extend({ }), L.resolveDefault(fs.exec_direct('/usr/libexec/acmesh-dnsinfo.sh'), ''), L.resolveDefault(fs.stat('/usr/lib/acme/client/dnsapi'), null), + L.resolveDefault(fs.lines('/proc/sys/kernel/hostname'), ''), ]); }, @@ -27,6 +28,8 @@ return view.extend({ let dnsApiInfoText = data[1]; let apiInfos = dnsapi.parseFile(dnsApiInfoText); let hasDnsApi = data[2] != null; + let hostname = data[3]; + let systemDomain = _guessDomain(hostname); let wikiUrl = 'https://github.com/acmesh-official/acme.sh/wiki/'; let wikiInstructionUrl = wikiUrl + 'dnsapi'; let m, s, o; @@ -97,6 +100,9 @@ return view.extend({ "The first name will be the subject name, subsequent names will be alt names. " + "Note that all domain names must point at the router in the global DNS.")); o.datatype = "list(string)"; + if (systemDomain) { + o.default = [systemDomain]; + } o.validate = function (section_id, value) { if (!value) { return true; @@ -271,6 +277,15 @@ return view.extend({ } }); +function _isFqdn(domain) { + // Is not an IP i.e. starts from alphanumeric and has least one dot + return /[a-z0-9-]\..*$/.test(domain) && !/[0-9-]\..*$/.test(domain); +} + +function _guessDomain(hostname) { + return _isFqdn(hostname) ? hostname : (_isFqdn(window.location.hostname) ? window.location.hostname : ''); +} + function _addDnsProviderField(s, apiId, opt, isOptsAlt) { let desc = '' + opt.Name + ' ' + opt.Description; diff --git a/applications/luci-app-acme/root/usr/share/rpcd/acl.d/luci-app-acme.json b/applications/luci-app-acme/root/usr/share/rpcd/acl.d/luci-app-acme.json index 97e5d65f5d..a8bd9f9fb3 100644 --- a/applications/luci-app-acme/root/usr/share/rpcd/acl.d/luci-app-acme.json +++ b/applications/luci-app-acme/root/usr/share/rpcd/acl.d/luci-app-acme.json @@ -4,6 +4,7 @@ "read": { "cgi-io": [ "exec" ], "file": { + "/proc/sys/kernel/hostname": [ "read" ], "/etc/ssl/acme": [ "list" ], "/usr/libexec/acmesh-dnsinfo.sh": [ "exec" ] },